import type { CardDetail, CardListData, CardListParams, CardParams, RuleListData, RuleListParams } from "@/types/card";
import { request } from "@/utils/reuqest";

/**
 * 获取月卡列表的API函数
 * 
 * 此函数通过发送GET请求到指定的API端点来获取卡片列表数据
 * 它使用了泛型方法request来处理HTTP请求和响应
 * 
 * @param params 查询卡片列表所需的参数，如页码、每页数量等
 * @returns 返回一个Promise对象，解析为CardListData类型的卡片列表数据
 */
export const getCardListAPI = (params: CardListParams) => {
  return request<CardListData>('/parking/card/list', 'GET', params)
}

/**
 * 新增月卡
 * @data
 * @returns
 */
export const createCardAPI = (data: Partial<CardParams>) => {
  return request('/parking/card', 'POST', data)
}

/**
 * 获取月卡详情
 * @data
 * @returns
 */
export const getCardDetailAPI = (id: string) => {
  return request<CardDetail>(`/parking/card/detail/${id}`,'GET')
} 

/**
 * 编辑月卡
 * @param {*} data
 * @returns
 */
export const updateCardAPI = (data: Partial<CardDetail>) => {
  return request('/parking/card/edit', 'PUT', data)
}

/**
 * 删除月卡
 * @param {*} ids
 * @returns
 */
export const delCarAPI = (ids: number[]) => {
  // 批量删除时，id用逗号隔开，通过 join 方法拼接字符串
  return request(`/parking/card/${ids.join(',')}`,'DELETE')
} 

/**
 * 获取规则列表
 * @param { page, pageSize} params
 * @returns
 */
export const getRuleListAPI = (params: RuleListParams) => {
  return request<RuleListData>('/parking/rule/list', 'GET', params)
} 